package com.yunhe.policyfulfillment.task;

import com.yunhe.common.model.ResultObject;
import com.yunhe.policyfulfillment.policyful.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName PublishTimedTasks
 * @Description TODO
 * @Author HeTao
 * @Date 2021/8/2 10:15
 * @Version 1.0
 **/
@Api(value = "PublishTimedTasks",description = "定时发布",tags = "{PublishTimed_Task}")
@RestController
@RequestMapping(value = "/publishTimed")
@Slf4j
public class PublishTimedTasks {


    @Autowired
    private IPolicyInfoMatterService policyInfoMatterService;

    @Autowired
    private PolicyInfoNewsService policyInfoNewsService;

    @Autowired
    private BannerService bannerService;

    @Autowired
    private PolicyInfoService policyInfoService;

    @Autowired
    private PolicyResultService policyResultService;

    @ApiOperation("定时发布")
    @RequestMapping(value ="/publishTimed",method = RequestMethod.POST)
    @Scheduled(cron = "0 0 0/1 * * ? ")
    @Async
    public ResultObject publishTimed(){
        log.info("定时发布数据定时任务开始");
        //定时发布事项
        policyInfoMatterService.publishTimedMatter();
        //定时发布新闻
        policyInfoNewsService.publishTimedNew();
        //定时发布Banner
        bannerService.publishTimedBanner();
        //定时发布政策
        policyInfoService.publishTimedPolicyInfo();
        //定时发布公式结果
        policyResultService.publishTimedPolicyResult();
        log.info("定时发布数据定时任务结束");
        return new ResultObject<>(null);
    }

    @ApiOperation("定时更新事项状态")
    @RequestMapping(value ="/publishTimedUpdateMatterStatus",method = RequestMethod.POST)
    @Scheduled(cron = "0 0 0 * * ? ")
    @Async
    public ResultObject publishTimedUpdateMatterStatus(){
        log.info("定时更新事项状态定时任务开始");
        //定时更新事项状态
        policyInfoMatterService.publishTimedUpdateMatterStatus();
        log.info("定时更新事项状态定时任务结束");
        return new ResultObject<>(null);
    }
}
